package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class PersonalCenterPage extends Utils {
    public static String url = "http://49.235.61.184/?s=user/index.html";

    public PersonalCenterPage() {
        super(url);
    }
    /**
     * 检查页面
     */
    public void checkPersonalCenterPage() throws IOException, InterruptedException {
        /*检查页面元素*/
        //检查头像
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.user-avatar > img"));
        //检查用户名
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.user-avatar > div > span"));
        //检查修改头像
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(1) > span"));
        //检查修改资料
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(2) > span"));
        //检查我的地址
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(3) > span"));
        //检查商品收藏
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > ul > li:nth-child(2) > a"));
        //检查我的足迹
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > ul > li:nth-child(3) > a"));
        //检查展示部分商品的购物车div
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.center-content.am-padding-lg.am-padding-top-0 > div.am-g.various > div:nth-child(2)"));
        //检查展示部分商品的商品收藏div
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.center-content.am-padding-lg.am-padding-top-0 > div.am-g.various > div:nth-child(3)"));
        //检查展示部分商品的我的足迹div
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.center-content.am-padding-lg.am-padding-top-0 > div.am-g.various > div:nth-child(4)"));
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());



        /*检查页面上的功能*/
        //检查”修改头像“
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(1) > i")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //刷新
        driver.navigate().refresh();

        //检查”修改资料“
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(2)")).click();
        //屏幕截图
        Thread.sleep(2000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查”我的地址“
        Thread.sleep(1000);
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > div.user-base-left > div.items > a:nth-child(3)")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查”商品收藏“
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > ul > li:nth-child(2) > a")).click();
        //屏幕截图
        Thread.sleep(2000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //检查”我的足迹“
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.user-base.am-radius > ul > li:nth-child(3) > a")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //获取当前的句柄
        String curwindow = driver.getWindowHandle();
        //检查购物车”更多“
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.am-container.user-main.user-center > div.user-content > div > div.center-content.am-padding-lg.am-padding-top-0 > div.am-g.various > div:nth-child(2) > div > div.am-panel-hd > a")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        Thread.sleep(2000);
        //获取所有句柄
        Set<String> windows = driver.getWindowHandles();
        for (String window:windows) {
            if (!window.equals(curwindow)){
                //切换页面
                driver.switchTo().window(window);
                //关闭页面
                driver.close();
            }
        }
        // 切回目标窗口
        driver.switchTo().window(curwindow);




    }
}
